package com.rkjoeson.player.view;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

public class RNTShortVideoList extends RecyclerView {

    public RNTShortVideoList(@NonNull Context context) {
        super(context);
    }

    public RNTShortVideoList(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RNTShortVideoList(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void requestLayout() {
        super.requestLayout();
        reLayout();
    }

    public void reLayout() {
        post(new Runnable() {
            @Override
            public void run() {
                if (getWidth() > 0 && getHeight() > 0) {
                    int w = MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY);
                    int h = MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY);
                    measure(w, h);
                    layout(getPaddingLeft() + getLeft(), getPaddingTop() + getTop(), getWidth() + getPaddingLeft() + getLeft(), getHeight() + getPaddingTop() + getTop());
                }
            }
        });
    }
}
